home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 4 / The Arsenal Files 4 (Arsenal Computer).ISO / casm / au116-as.exe / DELETE.CPP < prev    next >
C/C++ Source or Header  |  1994-12-13  |  6KB  |  247 lines

  1. // DELETE.CPP                                 1          1    6666
  2. // Dave Harris                                11         11   6
  3. // Compiled using Borland C++ ver 3.1       1 1        1 1   6666
  4. // 03-03-94                                  1     ..   1   6   6
  5. //                                           11111 .. 11111  666
  6. ////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "au.hpp"
  9.  
  10. /*********************************************************************/
  11. /* Define Statements */
  12. /*********************/
  13.  
  14. #define PROGRAM "DELETE"    // Name of module
  15.  
  16. typedef struct
  17. {
  18.     long change;
  19.     long total_bytes;
  20.     LISTPTR delete_list;
  21. } DELETE_INFO;
  22.  
  23. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  24. static BYTE fill_delete_spec(AU *au, LIST **el, LISTPTR *arc_list, char *string)
  25. {
  26.     LIST *a_el;
  27.     BYTE found = FALSE;
  28.  
  29.     string[0] = '\0';
  30.     for (;;)
  31.     {
  32.         for (a_el = arc_list->head; a_el != NULL; a_el = a_el->next)
  33.         {
  34.             if (wildcard_compare(au, a_el->data, (*el)->data))
  35.             {
  36.                 if (string[0] != '\0')
  37.                     strcat(string, " ");
  38.                 strcat(string, (*el)->data);
  39.                 found = TRUE;
  40.                 break;
  41.             }
  42.         }
  43.         *el = (*el)->next;
  44.         if (strlen(string) > 50 || *el == NULL)
  45.             break;
  46.     }
  47.     return found;
  48. }
  49. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  50. static BYTE delete_one(AU *au, char *file_name, LISTPTR *arc_list, PACKAGE *package)
  51. {
  52.     char   delete_file_spec[80];
  53.     char   string[FLENGTH];    /* build the dos commands in the string */
  54.     int    changed = FALSE;
  55.     int    did_rename;
  56.     LIST   *el;
  57.     DELETE_INFO *in = (DELETE_INFO *)au->info;
  58.  
  59.     if (package->del[0] == '\0')
  60.     {
  61.         au_printf_error(au, "No deleting method specified for %s", file_name);
  62.         press_any_key(au);
  63.         return FALSE;
  64.     }
  65.  
  66.     el = in->delete_list.head;
  67.     for (;;)
  68.     {
  69.         if (el == NULL)
  70.             break;
  71.         if (fill_delete_spec(au, &el, arc_list, delete_file_spec))
  72.         {
  73.             changed = TRUE;
  74.             au_printf(au, "@?6Deleting @?B%s @?6from @?1%s@?H\n", delete_file_spec,
  75.                       file_name);
  76.  
  77.             did_rename = rename_strict(au, package, au->source_directory, file_name);
  78.  
  79.             substitute_macros(string, package->del, NULL, NULL, NULL, file_name);
  80.             strcat(string, " ");
  81.             strcat(string, delete_file_spec);
  82.  
  83.             if (!au->simulate)
  84.                 execute(au, string, au->output, NULL, package->memoryNeeded);
  85.             if (did_rename)
  86.                 rename_strict_back(au->source_directory, file_name);
  87.         }
  88.     }
  89.     if (changed)
  90.         fix_flist(au, file_name, file_name);
  91.  
  92.     return changed;
  93. }
  94. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  95. static void get_file_list(AU *au, char *file_name, ARC_HANDLE *arc_handle,
  96.                           LISTPTR *arc_list)
  97. {
  98.     int ret_code;
  99.     ARC_RECORD record;
  100.  
  101.     for (;;)
  102.     {
  103.         ret_code = arc_handle->get_record(au, &record);
  104.         if (ret_code == EOF)
  105.             break;
  106.         else if (ret_code == -2)
  107.         {
  108.             add_to_bad_list(au, au->source_directory, file_name);
  109.             return;
  110.         }
  111.         arc_list->add(record.name);
  112.     }
  113.     return;
  114. }
  115. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  116. static int delete_func(AU *au, char *file_name)
  117. {
  118.     HANDLE       handle;
  119.     ARC_HANDLE arc_handle;
  120.     struct       ftime ftime_hold;
  121.     struct       ffblk ffblk;
  122.     long       fsize_before;
  123.     LISTPTR    arc_list;
  124.     DELETE_INFO *in = (DELETE_INFO *)au->info;
  125.  
  126.     check_for_key();
  127.  
  128.     arc_handle.init(au, file_name);
  129.     arc_handle.get_time(&ftime_hold);
  130.     if (arc_handle.type > 0)
  131.     {
  132.         get_file_list(au, file_name, &arc_handle, &arc_list);
  133.         arc_handle.deinit(au);
  134.  
  135.         findfirst(file_name, &ffblk, 0);
  136.         fsize_before = ffblk.ff_fsize;
  137.         in->total_bytes += fsize_before;
  138.  
  139.         if (delete_one(au, file_name, &arc_list, &au->package[arc_handle.type]))
  140.         {
  141.             findfirst(file_name, &ffblk, 0);
  142.             in->change += ffblk.ff_fsize - fsize_before;
  143.  
  144.             au->number_processed++;
  145.             if (au->date_retain == ON)
  146.             {
  147.                 if (handle.open(au, file_name, O_RDONLY | O_BINARY) == SUCCESS)
  148.                 {
  149.                     handle.set_time(&ftime_hold);
  150.                     handle.close();
  151.                 }
  152.             }
  153.         }
  154.         arc_list.destroy();
  155.     }
  156.     else
  157.         arc_handle.deinit(au);
  158.  
  159.     return 0;
  160. }
  161. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  162. static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
  163.                             PARSE_TYPE type)
  164. {
  165.     DELETE_INFO *in = (DELETE_INFO *)au->info;
  166.  
  167.     switch (type)
  168.     {
  169.     case PARSE_PARAM_OPTION:
  170.         switch (option)
  171.         {
  172.         case 'D':
  173.             au->date_retain = get_value(au, OFF | ON);
  174.             break;
  175.         case '@':
  176.             process_at_file(au, &in->delete_list, cur_argv);
  177.             break;
  178.         case '?':
  179.             au_syntax_message(au, "DElete");
  180.             au_printf(au,
  181.                 "[@?3options@?H] @?1archive_filespec @?Bdelete_filespec(s)@?H\n\n");
  182.             au_param_heading(au);
  183.             au_printf(au,
  184.                 "@?3-@@?Hfile           File containing list of files to delete\n"
  185.                 "@?3-D@?Hon|off         Date retain\n");
  186.             exit (0);
  187.         default:
  188.             au_invalid_option(au, PROGRAM, option);
  189.         }
  190.         return TRUE;
  191.     case PARSE_FILESPEC:
  192.         if (au->process_list.head == NULL)
  193.             au->process_list.add(cur_argv);
  194.         else
  195.         {
  196.             if (stricmp(cur_argv, "*.*") == 0)
  197.             {
  198.                 int opt;
  199.                 au_printf_c(au, 15, "*.* Will strip all files from the archives, proceed?");
  200.                 opt = my_getch();
  201.                 au_printf(au, "\n");
  202.                 if (opt=='N' || opt=='n')
  203.                     exit(0);
  204.             }
  205.             in->delete_list.add(cur_argv);
  206.         }
  207.         return TRUE;
  208.     case PARSE_POST_CHECK:
  209.         if (au->process_list.head == NULL)
  210.         {
  211.             au_printf_error(au, "No Archive file specified");
  212.             exit(0);
  213.         }
  214.         if (in->delete_list.head == NULL)
  215.         {
  216.             au_printf_error(au, "No delete file_spec specified");
  217.             exit(0);
  218.         }
  219.         return TRUE;
  220.     }
  221.     return FALSE;
  222. }
  223. /*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
  224. int main_delete(AU *au, int argc, char *argv[])
  225. {
  226.     DELETE_INFO *in;
  227.  
  228.     in = new DELETE_INFO;
  229.     memset(in, '\0', sizeof(DELETE_INFO));
  230.     au->info = in;
  231.  
  232.     ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, NULL);
  233.     generic_parse_comm_line(au, argc, argv, parse_comm_line);
  234.  
  235.     process_files(au, delete_func);
  236.  
  237.     if (!au->no_extra)
  238.     {
  239.         au_printf_c(au, 15, "\n\nFiles Processed = %d\n", au->number_processed);
  240.         au_printf_c(au, 15, "Total Bytes   Saved   = %ld\n", -in->change);
  241.         au_printf_c(au, 15, "Total Percent Saved   = %s\n",
  242.            ltrim(percent_string(in->total_bytes, in->total_bytes+in->change)));
  243.     }
  244.     return (0);
  245. }
  246.  
  247.